package com.kinyx.framework.processor;

import javax.annotation.processing.Messager;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.tools.Diagnostic;

public class Logger {

	private Messager messager;

	public Logger(final Messager messager) { super(); this.messager = messager; }

	private void log(final Diagnostic.Kind kind, final String msg) {
		this.messager.printMessage(kind, msg);
		System.out.println(String.format("[%s]%s", kind.toString(), msg));
	}
	public void ERROR(final String msg) { this.log(Diagnostic.Kind.ERROR, msg); }
	public void WARNING(final String msg) { this.log(Diagnostic.Kind.WARNING, msg); }
	public void MANDATORY_WARNING(final String msg) { this.log(Diagnostic.Kind.MANDATORY_WARNING, msg); }
	public void NOTE(final String msg) { this.log(Diagnostic.Kind.NOTE, msg); }
	public void OTHER(final String msg) { this.log(Diagnostic.Kind.OTHER, msg); }

	private void log(final Diagnostic.Kind kind, final String msg, final Element e) {
		this.messager.printMessage(kind, msg, e);
		System.out.println(String.format("[%s]%s {Element:%s}", kind.toString(), msg, e.getSimpleName()));
	}
	public void ERROR(final String msg, final Element e) { this.log(Diagnostic.Kind.ERROR, msg, e); }
	public void WARNING(final String msg, final Element e) { this.log(Diagnostic.Kind.WARNING, msg, e); }
	public void MANDATORY_WARNING(final String msg, final Element e) { this.log(Diagnostic.Kind.MANDATORY_WARNING, msg, e); }
	public void NOTE(final String msg, final Element e) { this.log(Diagnostic.Kind.NOTE, msg, e); }
	public void OTHER(final String msg, final Element e) { this.log(Diagnostic.Kind.OTHER, msg, e); }

	private void log(final Diagnostic.Kind kind, final String msg, final Element e, final AnnotationMirror a) {
		this.messager.printMessage(kind, msg, e, a);
		System.out.println(String.format("[%s]%s {Element:%s,AnnotationMirror:%s}", kind.toString(), msg, e.getSimpleName(), String.valueOf(a)));
	}
	public void ERROR(final String msg, final Element e, final AnnotationMirror a) { this.log(Diagnostic.Kind.ERROR, msg, e, a); }
	public void WARNING(final String msg, final Element e, final AnnotationMirror a) { this.log(Diagnostic.Kind.WARNING, msg, e, a); }
	public void MANDATORY_WARNING(final String msg, final Element e, final AnnotationMirror a) { this.log(Diagnostic.Kind.MANDATORY_WARNING, msg, e, a); }
	public void NOTE(final String msg, final Element e, final AnnotationMirror a) { this.log(Diagnostic.Kind.NOTE, msg, e, a); }
	public void OTHER(final String msg, final Element e, final AnnotationMirror a) { this.log(Diagnostic.Kind.OTHER, msg, e, a); }

	private void log(final Diagnostic.Kind kind, final String msg, final Element e, final AnnotationMirror a, final AnnotationValue v) {
		this.messager.printMessage(kind, msg, e, a, v);
		System.out.println(String.format("[%s]%s {Element:%s,AnnotationMirror:%s,AnnotationValue:%s}", kind.toString(), msg, e.getSimpleName(), String.valueOf(a), String.valueOf(v)));
	}
	public void ERROR(final String msg, final Element e, final AnnotationMirror a, final AnnotationValue v) { this.log(Diagnostic.Kind.ERROR, msg, e, a, v); }
	public void WARNING(final String msg, final Element e, final AnnotationMirror a, final AnnotationValue v) { this.log(Diagnostic.Kind.WARNING, msg, e, a, v); }
	public void MANDATORY_WARNING(final String msg, final Element e, final AnnotationMirror a, final AnnotationValue v) { this.log(Diagnostic.Kind.MANDATORY_WARNING, msg, e, a, v); }
	public void NOTE(final String msg, final Element e, final AnnotationMirror a, final AnnotationValue v) { this.log(Diagnostic.Kind.NOTE, msg, e, a, v); }
	public void OTHER(final String msg, final Element e, final AnnotationMirror a, final AnnotationValue v) { this.log(Diagnostic.Kind.OTHER, msg, e, a, v); }

}
